﻿using System.Runtime.CompilerServices;

namespace Digitalmes.AvaloniaUI.Infrastructure;

/// <summary>
/// 简易的 ViewModel 基类，通过实现 <see cref="INotifyPropertyChanged"/> 来通知 View 端有属性发生了变化。
/// </summary>
public abstract class PropertyChangedBase : INotifyPropertyChanged
{
    /// <summary>
    /// <see cref="INotifyPropertyChanged"/> 实现事件。
    /// </summary>
    public event PropertyChangedEventHandler? PropertyChanged;

    /// <summary>
    /// 抛出属性更改事件。
    /// </summary>
    /// <param name="propertyName">定义了 CallerMemberNameAttribute 特性，执行时默认为当前更改的属性名称。</param>
    protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
